package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.UnitDao;
import com.atguigu.jxc.entity.Log;
import com.atguigu.jxc.entity.Unit;
import com.atguigu.jxc.service.LogService;
import com.atguigu.jxc.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UnitServiceImpl implements UnitService {

    @Autowired
    private UnitDao unitDao;

    @Autowired
    private LogService logService;

    @Override
    public Map<String, Object> unitList() {
        Map<String, Object> map = new HashMap<>();
        List<Unit> unitList = unitDao.unitList();
        List<Map<String,Object>> mapList = new ArrayList<>();

        for (Unit unit : unitList) {
            Map<String,Object> unitMap = new HashMap<>();
            unitMap.put("unitId",unit.getUnitId());
            unitMap.put("unitName",unit.getUnitName());
            mapList.add(unitMap);
            logService.save(new Log(Log.SELECT_ACTION,"查询unit数据"+unit.getUnitId()));
        }
        map.put("rows",unitList);


        return map;
    }
}
